<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>


<script type="text/javascript">
    //分页 js
    $(function () {
//选择table的id.datagrid控件
        $("#tableal").datagrid({
            url: "${pageContext.request.contextPath}/fyalbum",
//是否显示分页
            pagination: true,
            toolbar: "#dell",
//标题信息
            fit: true,
            title: "用户信息表",
            //width: 499,
            //height: 339,
            onDblClickRow: function (rowIndex, rowData) {
                $("#updatee").panel("open");

                $("#upalbumId").val(rowData.albumId);
                $("#upalbumName").val(rowData.albumName);
                $("#upalbumAuthor").val(rowData.albumAuthor);
                $("#upalbumTeller").val(rowData.albumTeller);
                $("#upalbumEpisodes").val(rowData.albumEpisodes);
                $("#upalbumContent").val(rowData.albumContent);
                $("#upalbumImage").val(rowData.albumImage);
                $("#upalbumStar").val(rowData.albumStar);

            },


//显示数据
            columns: [[

                {checkbox: true},
                {field: 'id', title: '专辑编号'},
                {field: 'name', title: '专辑名称'},
                {
                    field: 'albumImage', title: '专辑封面', formatter: function (value, rowData, rowIndex) {

                        if (value != undefined) {
                            var tp = "<img width='75xp' height='30xp' src='${pageContext.request.contextPath}" + value + "'>";
                            console.info(tp);
                            return tp;
                        }
                        console.info(value);
                    }
                },
                {field: 'albumAuthor', title: '专辑作者'},
                {field: 'albumTeller', title: '专辑播音'},
                {field: 'albumEpisodes', title: '专辑集数'},
                {field: 'albumDate', title: '出版日期'},
                {field: 'albumContent', title: '内容简介'},
                {field: 'albumStar', title: '专辑评分'},
                {field: 'albumState', title: '专辑状态', formatter: function (value, rowData, rowIndex){
                    if(value==0){
                        return "正常";
                    }else{
                        return "已删除";
                    }

                    }},
            ]],



        });


        $("#insert0").dialog({

            title: "添加",
            closed: true,
            width: 300,
            height: 300,
        });

        $("#updatee").dialog({

            title: "修改",
            closed: true,
            width: 400,
            height: 400,
        });


    });

    function tj() {
        $("#insert0").window("open");
    }




    function jd() {
        var de = $("#tableal").datagrid("getSelections");
        if (de.length == 0) {
            $.messager.alert('我的消息', '亲,您什么都没有选中哦！', 'warning');
        } else {

            $.messager.confirm('我的消息', '亲,确定要删除此专辑吗！', function (s) {
                if (s) {

                    var id = new Array();

                    for (var i = 0; i < de.length; i++) {
                        //           实体类id
                        id[i] = de[i].id;
                    }
                    alert(id);
                    $.ajax({
                        url: "${pageContext.request.contextPath}/deleteAlbum",
                        //    controller收参id
                        data: "id=" + id,
                        type: "post",
                        success: function (m) {
                            if (m.mydeleteAlbum) {
                                $("#tableal").datagrid("load");
                                $.messager.alert('我的消息', '删除成功！', 'info');
                            } else {
                                $.messager.alert('我的消息', '失败,请重试！', 'info');
                            }

                        }
                    });
                }

            });

        }
    }

    function tijiao2() {
        $("#formm").form("submit",{

            url:"${pageContext.request.contextPath}/addAlbum",
            onSubmit:function(){
                return true;
            },
            //dateType:"json",
            success:function(data){
                var s = JSON.parse(data);
                if(s.myadd){
                    $("#insert0").window("close");
                    $("#tableal").datagrid("load");
                    $.messager.alert('我的消息', '添加成功！', 'info');
                }else{
                    $.messager.alert('我的消息', '添加失败！', 'info');
                }
            }
        })
    }

    function tijiao3() {
        $("#uupp").form("submit", {
            url: "${pageContext.request.contextPath}/updateAlbum",

            success: function (s) {
                var data = JSON.parse(s);
                if (data.myupdateAlbum) {
                    $("#updatee").panel("close");
                    $("#tableal").datagrid("load");
                    $.messager.alert('提示', '修改成功!', 'info');
                } else {
                    $.messager.alert('提示', '修改失败,请重试!', 'warning');
                }

            }
        });

    }
</script>
<table id="tableal"></table>

<div id="dell">
    <%--<a id="dj" class="easyui-linkbutton" onclick="dj()">冻结</a>--%>
    <a id="jd" class="easyui-linkbutton" onclick="jd()">删除</a>
    <a id="tj" class="easyui-linkbutton" onclick="tj()">添加</a>
</div>

<div id="insert0">
    <form id="formm" method="post" enctype="multipart/form-data">
        专辑名称:<input type="text" name="albumName" id="albumName"><br/>
        专辑作者:<input type="text" name="albumAuthor" id="albumAuthor"><br/>
        专辑播音:<input type="text" name="albumTeller" id="albumTeller"><br/>
        专辑集数:<input type="text" name="albumEpisodes" id="albumEpisodes"><br/>
        专辑内容简介:<input type="text" name="albumContent" id="albumContent"><br/>
        专辑封面:<input type="file" name="photo" id="photo"><br/>
        专辑评分:<input type="text" name="albumStar" id="albumStar"><br/>
        <input type="button" value="提交" onclick="tijiao2()">
    </form>
</div>

<div id="updatee">
    <form id="uupp" method="post" enctype="multipart/form-data">
        专辑名称:<input type="hidden" name="albumId" id="upalbumId"><br/>
        专辑名称:<input type="text" name="albumName" id="upalbumName"><br/>
        专辑作者:<input type="text" name="albumAuthor" id="upalbumAuthor"><br/>
        专辑播音:<input type="text" name="albumTeller" id="upalbumTeller"><br/>
        专辑集数:<input type="text" name="albumEpisodes" id="upalbumEpisodes"><br/>
        专辑内容简介:<input type="text" name="albumContent" id="upalbumContent"><br/>
        专辑封面:<input type="file" name="photo" id="upphoto"><br/>
        专辑评分:<input type="text" name="albumStar" id="upalbumStar"><br/>
        <input type="button" value="提交" onclick="tijiao3()">
    </form>
</div>